package org.komarichin.jpa.service;

import org.komarichin.jpa.entity.IRole;
import org.komarichin.jpa.entity.IUser;
import org.komarichin.jpa.service.exceptions.DublicateUserException;

import java.io.Serializable;
import java.util.List;

/**
 * User: Michael Komarichin
 * Date: 28.09.2009
 * Time: 13:24:05
 */
public interface IUserService extends Serializable {

    final String SYSTEM_ROLE = "SYSTEM";
    final String USER_ROLE = "USER";

    /**
     * find role by id
     *
     * @param id role id
     * @return found role
     */
    IRole getRoleById(Long id);

    /**
     * @return all roles
     */
    List<IRole> getAllRoles();

    /**
     * find role for users
     *
     * @param permission user permission
     * @return found roles
     */
    List<IRole> getAllowRoles(Long permission);

    /**
     * @param object saved role
     */
    void saveRole(IRole object);

    /**
     * @param object updated role
     */
    void updateRole(IRole object);

    /**
     * @param object save or update role, if role exist then update
     */
    void saveOrUpdateRole(IRole object);

    /**
     * @param object delete role
     */
    void deleteRole(IRole object);

    /**
     * fidn role by name
     *
     * @param name role name
     * @return found role or null
     */
    IRole getRoleByName(String name);

    /**
     * find user by it id
     *
     * @param id news id
     * @return found news
     */
    IUser getUserById(Long id);


    /**
     * @return all users in list, if users not exists then list will empty with size 0
     */
    List<IUser> getAllUsers();

    /**
     * @param object save persistence user
     */
    void saveUser(IUser object);

    /**
     * @param object update news
     */
    void updateUser(IUser object);

    /**
     * @param object save or update user if user exists then it will be save
     */
    void saveOrUpdateUser(IUser object);

    /**
     * @param object delete user
     */
    void deleteUser(IUser object);

    /**
     * Create new user
     *
     * @param login    user login
     * @param password user password
     * @param hint     user hint
     * @return new created user
     * @throws org.komarichin.jpa.service.exceptions.DublicateUserException
     *          a
     */
    IUser enroll(String login, String password, String hint) throws DublicateUserException;

    /**
     * find user by login and password
     *
     * @param login    user login
     * @param password user password
     * @return found user or null
     */
    IUser login(String login, String password);

    /**
     * find user by login and hint if user lost your password
     *
     * @param login user login
     * @param hint  user hint
     * @return found user or null
     */
    IUser forgot(String login, String hint);

    /**
     * find user by login
     *
     * @param login user login
     * @return found user
     */
    IUser findByName(String login);

    /**
     * check user in bd
     *
     * @param login user login
     * @return true if user exists
     */
    boolean isUserExists(String login);

    /**
     * find user by customer permission
     *
     * @param permission customer permission
     * @return found users
     */
    List<IUser> getAllowUsers(Long permission);

    /**
     *
     * @return create or get system role by name SYSTEM
     */
    IRole createSystemRole();
}
